-----------------------------------
-- Area: Windurst Woods
-- NPC: Amimi
-- Type: Chocobo Renter
-- @zone 241
-- @pos 136.112 -5.250 -121.850
-----------------------------------
package.loaded["scripts/zones/Windurst_Woods/TextIDs"] = nil;
-----------------------------------

require("scripts/globals/settings");
require("scripts/globals/keyitems");
require("scripts/globals/status");
require("scripts/globals/quests");

-----------------------------------
-- onTrade Action
-----------------------------------

function onTrade(player,npc,trade)
    local hasLicense = player:hasKeyItem(CHOCOBO_LICENSE);
    local level = player:getMainLvl();
    local count = trade:getItemCount();
    local ChocoboTicket = trade:hasItemQty(1514,1);
    local Chocopass = trade:hasItemQty(1789,1);
    local durationMod = player:getMod(MOD_CHOCOBO_TIME) * 60;

    if(ChocoboTicket == true and count == 1) then
        if (hasLicense and level >= 20) then
            player:tradeComplete();
            player:addStatusEffectEx(EFFECT_CHOCOBO,EFFECT_CHOCOBO,1,0,(1800 + durationMod),true);
            player:setPos(-122,-4,-520,0,0x74);
        end
    elseif(Chocobopass == true and count == 1) then
        player:tradeComplete();
        player:addStatusEffectEx(EFFECT_CHOCOBO,EFFECT_CHOCOBO,1,0,(120 + durationMod),true);
        player:setPos(-122,-4,-520,0,0x74);
    end

end;

-----------------------------------
-- onTrigger Action
-----------------------------------

function onTrigger(player,npc)
    local price = 100;
    local gil = player:getGil();
    local hasLicense = player:hasKeyItem(CHOCOBO_LICENSE);
    local level = player:getMainLvl();
    local ChocobosWounds = player:getQuestStatus(JEUNO,CHOCOBO_S_WOUNDS);

    if ((hasLicense and level >= 15) or (level >=15 and ChocobosWounds == QUEST_COMPLETED)) then
        player:startEvent(0x2714,price,gil);
    else
        player:startEvent(0x2717,price,gil);
    end

end;

-----------------------------------
-- onEventFinish Action
-----------------------------------
function onEventFinish(player,csid,option)
    -- printf("CSID: %u",csid);
    -- print("OPTION:",option);
    local durationMod = player:getMod(MOD_CHOCOBO_TIME) * 60;
    local price = 100;

    if (csid == 0x2714 and option == 0) then
        if (player:delGil(price)) then
            if (player:getMainLvl() >= 20) then
                player:addStatusEffectEx(EFFECT_CHOCOBO,EFFECT_CHOCOBO,1,0,(1800 + durationMod),true);
            else
                player:addStatusEffectEx(EFFECT_CHOCOBO,EFFECT_CHOCOBO,1,0,(900 + durationMod),true);
            end
            player:setPos(-122,-4,-520,0,0x74);
        end
    end

end;